package cn.com.computer.my.computer.music.web;

import cn.com.computer.common.base.bean.CandyResult;
import cn.com.computer.common.utils.helper.ParamUtils;
import cn.com.computer.my.computer.music.service.MusicService;
import cn.com.computer.my.computer.music.web.bean.MusicBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by WANGXin on 2017/5/21.
 */
@Controller
@RequestMapping(value = "/computer/music")
public class MusicController {

    private static final Logger LOGGER = LoggerFactory.getLogger(MusicController.class);

    @Autowired
    private MusicService musicService;

    @RequestMapping(value = "commit/save", method = RequestMethod.POST)
    @ResponseBody
    public CandyResult save(MusicBean musicBean, HttpServletRequest request, HttpServletResponse response){
        CandyResult candyResult = new CandyResult();
        try {
            candyResult = musicService.save(musicBean);
        }catch (Exception e){
            LOGGER.error("保存音乐信息异常，异常数据为:[" + ParamUtils.serializable(musicBean) + "]",e);
            candyResult.setMessage("保存音乐信息失败");
        }

        return candyResult;
    }

}
